﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Services;
using System.Collections;

namespace Catering.Catering_Page.system
{
    public partial class Units : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.LoadRep();
            }
        }

        //加载Rep
        public void LoadRep()
        {
            DataTable dt_Units = new Catering_Rules.Units().GetAllList().Tables[0];
            this.Rep_OperationArea.DataSource = dt_Units;
            this.Rep_OperationArea.DataBind();
        }

        //获取
        [WebMethod]
        public static ArrayList Get(string cid)
        {
            ArrayList al = new ArrayList();
            Catering_Model.Units md = new Catering_Rules.Units().GetModel(Convert.ToInt32(cid));
            al.Add(md.UName);
            al.Add(md.Back);
            return al;
        }

        //添加
        [WebMethod]
        public static string Add(string CName, string Back)
        {
            Catering_Model.Units md = new Catering_Model.Units();
            md.id = new Catering_Rules.Units().GetMaxId();
            md.UName = CName;
            md.Back = Back;
            new Catering_Rules.Units().Add(md);
            return "OK";
        }

        //修改
        [WebMethod]
        public static string Edit(string cid,string CName, string Back)
        {
            Catering_Model.Units md = new Catering_Model.Units();
            md.id = Convert.ToInt32(cid);
            md.UName = CName;
            md.Back = Back;
            new Catering_Rules.Units().Update(md);
            return "OK";
        }

        //删除
        protected void Rep_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                int delID = Convert.ToInt32(e.CommandArgument);
                if (new Catering_Rules.Units().Delete(delID))
                {
                    this.LoadRep();
                }
            }
        }
    }
}